Fix return type for CollectionRef::new
authorFelix Krull <f_krull@gmx.de>
Sat, 18 May 2019 12:48:11 +0000 (14:48 +0200)
committerColin Walters <walters@verbum.org>
Fri, 6 May 2022 16:53:53 +0000 (12:53 -0400)
gir doesn't seem to generate this correctly. I have no clue why, there
are certainly some functions where nullable=1 causes an Option return.

rust-bindings/rust/gir-files/OSTree-1.0.gir
rust-bindings/rust/src/collection_ref.rs [deleted file]
rust-bindings/rust/src/collection_ref/mod.rs [new file with mode: 0644]

index 33df3aa38deee2a2718e3a2512971d28aa26587c..e144a27032966352b19b89a121b1fca31b91edb2 100644 (file)
@@ -917,7 +917,7 @@ indicating a ref name which is not globally unique.</doc>
 @collection_id is %NULL, this is equivalent to a plain ref name string (not a
 refspec; no remote name is included), which can be used for non-P2P
 operations.</doc>
-        <return-value transfer-ownership="full">
+        <return-value transfer-ownership="full" nullable="1">
           <doc xml:space="preserve">a new #OstreeCollectionRef</doc>
           <type name="CollectionRef" c:type="OstreeCollectionRef*"/>
         </return-value>
diff --git a/rust-bindings/rust/src/collection_ref.rs b/rust-bindings/rust/src/collection_ref.rs
deleted file mode 100644 (file)
index 27374e3..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-// Based on a file generated by gir. Changes are marked below.
-use ffi;
-use glib::translate::*;
-use glib_ffi;
-use gobject_ffi;
-use std::hash;
-use std::mem;
-use std::ptr;
-
-glib_wrapper! {
-    #[derive(Debug, PartialOrd, Ord)]
-    pub struct CollectionRef(Boxed<ffi::OstreeCollectionRef>);
-
-    match fn {
-        copy => |ptr| gobject_ffi::g_boxed_copy(ffi::ostree_collection_ref_get_type(), ptr as *mut _) as *mut ffi::OstreeCollectionRef,
-        free => |ptr| gobject_ffi::g_boxed_free(ffi::ostree_collection_ref_get_type(), ptr as *mut _),
-        get_type => || ffi::ostree_collection_ref_get_type(),
-    }
-}
-
-impl CollectionRef {
-    #[cfg(any(feature = "v2018_6", feature = "dox"))]
-    pub fn new<'a, P: Into<Option<&'a str>>>(collection_id: P, ref_name: &str) -> CollectionRef {
-        let collection_id = collection_id.into();
-        let collection_id = collection_id.to_glib_none();
-        unsafe {
-            from_glib_full(ffi::ostree_collection_ref_new(collection_id.0, ref_name.to_glib_none().0))
-        }
-    }
-
-    #[cfg(any(feature = "v2018_6", feature = "dox"))]
-    fn equal(&self, ref2: &CollectionRef) -> bool {
-        unsafe {
-            // CHANGE: both instances of *mut to *const
-            from_glib(ffi::ostree_collection_ref_equal(ToGlibPtr::<*const ffi::OstreeCollectionRef>::to_glib_none(self).0 as glib_ffi::gconstpointer, ToGlibPtr::<*const ffi::OstreeCollectionRef>::to_glib_none(ref2).0 as glib_ffi::gconstpointer))
-        }
-    }
-
-    #[cfg(any(feature = "v2018_6", feature = "dox"))]
-    fn hash(&self) -> u32 {
-        unsafe {
-            // CHANGE: *mut to *const
-            ffi::ostree_collection_ref_hash(ToGlibPtr::<*const ffi::OstreeCollectionRef>::to_glib_none(self).0 as glib_ffi::gconstpointer)
-        }
-    }
-}
-
-impl PartialEq for CollectionRef {
-    #[inline]
-    fn eq(&self, other: &Self) -> bool {
-        self.equal(other)
-    }
-}
-
-impl Eq for CollectionRef {}
-
-impl hash::Hash for CollectionRef {
-    #[inline]
-    fn hash<H>(&self, state: &mut H) where H: hash::Hasher {
-        hash::Hash::hash(&self.hash(), state)
-    }
-}
diff --git a/rust-bindings/rust/src/collection_ref/mod.rs b/rust-bindings/rust/src/collection_ref/mod.rs
new file mode 100644 (file)
index 0000000..dd93cb4
--- /dev/null
@@ -0,0 +1,66 @@
+// Based on a file generated by gir. Changes are marked below.
+use ffi;
+use glib::translate::*;
+use glib_ffi;
+use gobject_ffi;
+use std::hash;
+use std::mem;
+use std::ptr;
+
+glib_wrapper! {
+    #[derive(Debug, PartialOrd, Ord)]
+    pub struct CollectionRef(Boxed<ffi::OstreeCollectionRef>);
+
+    match fn {
+        copy => |ptr| gobject_ffi::g_boxed_copy(ffi::ostree_collection_ref_get_type(), ptr as *mut _) as *mut ffi::OstreeCollectionRef,
+        free => |ptr| gobject_ffi::g_boxed_free(ffi::ostree_collection_ref_get_type(), ptr as *mut _),
+        get_type => || ffi::ostree_collection_ref_get_type(),
+    }
+}
+
+impl CollectionRef {
+    #[cfg(any(feature = "v2018_6", feature = "dox"))]
+    // CHANGE: return type CollectionRef to Option<CollectionRef>
+    pub fn new<'a, P: Into<Option<&'a str>>>(collection_id: P, ref_name: &str) -> Option<CollectionRef> {
+        let collection_id = collection_id.into();
+        let collection_id = collection_id.to_glib_none();
+        unsafe {
+            from_glib_full(ffi::ostree_collection_ref_new(collection_id.0, ref_name.to_glib_none().0))
+        }
+    }
+
+    #[cfg(any(feature = "v2018_6", feature = "dox"))]
+    fn equal(&self, ref2: &CollectionRef) -> bool {
+        unsafe {
+            // CHANGE: both instances of *mut to *const
+            from_glib(ffi::ostree_collection_ref_equal(ToGlibPtr::<*const ffi::OstreeCollectionRef>::to_glib_none(self).0 as glib_ffi::gconstpointer, ToGlibPtr::<*const ffi::OstreeCollectionRef>::to_glib_none(ref2).0 as glib_ffi::gconstpointer))
+        }
+    }
+
+    #[cfg(any(feature = "v2018_6", feature = "dox"))]
+    fn hash(&self) -> u32 {
+        unsafe {
+            // CHANGE: *mut to *const
+            ffi::ostree_collection_ref_hash(ToGlibPtr::<*const ffi::OstreeCollectionRef>::to_glib_none(self).0 as glib_ffi::gconstpointer)
+        }
+    }
+}
+
+impl PartialEq for CollectionRef {
+    #[inline]
+    fn eq(&self, other: &Self) -> bool {
+        self.equal(other)
+    }
+}
+
+impl Eq for CollectionRef {}
+
+impl hash::Hash for CollectionRef {
+    #[inline]
+    fn hash<H>(&self, state: &mut H) where H: hash::Hasher {
+        hash::Hash::hash(&self.hash(), state)
+    }
+}
+
+#[cfg(test)]
+mod tests;